<template>
  <div class="container2 " :style="{ left: userStore.asideWidth }">
    <el-tabs class="fm-tabs" @tab-change="changeTab" @tab-remove="removeTab" v-model="activeTab" type="card">
      <el-tab-pane v-for="item in tabList" :closable="item.path !== '/'" :key="item.path" :label="item.title"
        :name="item.path">
      </el-tab-pane>
    </el-tabs>
    <span class="fm-dropdown">
      <el-dropdown @command="handleCommand">
        <span class="el-dropdown-link">
          <el-icon class="el-icon--right">
            <arrow-down />
          </el-icon>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item command="clearOther">清除其他</el-dropdown-item>
            <el-dropdown-item command="clearAll">清除所有</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </span>
  </div>
</template>
<script lang="ts" setup>
import { useInfoStore } from '../../store';
import { ArrowDown } from '@element-plus/icons-vue'
import { useMain } from '../../composables/useMain';
import { onBeforeRouteUpdate } from 'vue-router';
const {
  tabList,
  activeTab,
  addTab,
  removeTab,
  handleCommand,
  changeTab,
  initTabLists,
} = useMain();
const userStore = useInfoStore();
/** 当前路由发生改变时触发 */
onBeforeRouteUpdate((to) => {
  userStore.routePath = to.path;
  // console.log('打印userStore.routePath', userStore.routePath);
  activeTab.value = userStore.routePath;
  addTab({
    title: to.meta.title,
    path: to.path,
  });
});
initTabLists();

</script>
<style scoped lang='scss'>
.container2 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  top: 64px;
  right: 0;
  height: 44px;
  z-index: 100;
}



.fm-tabs {
  display: flex;
  justify-content: center;
}

.fm-dropdown {
  position: fixed;
  right: 0px;
  padding-right: 30px;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: centers;
}

.el-dropdown-link {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 32px;
  height: 32px;
  background-color: #fff;
  cursor: pointer;
}

:deep(.el-tabs--card>.el-tabs__header) {
  border: 0px;
  margin: 0px;

}

.el-icon--right {
  margin: 0px;
}

:deep(.el-tabs--card>.el-tabs__header .el-tabs__nav) {
  border: 0;
}

:deep(.el-tabs--card>.el-tabs__header .el-tabs__item) {
  background-color: #fff;
  margin-right: 10px;
  border: 0;
}

:deep(.is-disabled) {
  color: #fff;
}

@media (min-width: 1536px) {
  .container {
    max-width: 100%;
  }
}

@media (min-width: 1024px) {
  .container {
    max-width: 100%;
  }
}

@media (min-width: 640px) {
  .container {
    max-width: 100%;
  }
}
</style>
